package com.ruoyi.web.controller.meituanSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MeituanSettings;
import com.ruoyi.system.service.IMeituanSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 美团点评API配置Controller
 *
 * @author ruoyi
 * @date 2025-05-14
 */
@Api(tags="团点评API配置")
@RestController
@RequestMapping("/system/meituanSettings")
public class MeituanSettingsController extends BaseController
{
    @Autowired
    private IMeituanSettingsService meituanSettingsService;

    /**
     * 通过门店名称查询美团点评API配置列表
     */
    @ApiOperation("通过门店名称查询美团点评API配置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<MeituanSettings> list = meituanSettingsService.selectMeituanSettingsListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出美团点评API配置列表
     */
    @ApiOperation("导出美团点评API配置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:export')")
    @Log(title = "美团点评API配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<MeituanSettings> list = meituanSettingsService.selectMeituanSettingsListByName(storeName);
        ExcelUtil<MeituanSettings> util = new ExcelUtil<MeituanSettings>(MeituanSettings.class);
        util.exportExcel(response, list, "美团点评API配置数据");
    }

    /**
     * 通过id获取美团点评API配置详细信息
     */
    @ApiOperation("通过id获取美团点评API配置详细信息")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(meituanSettingsService.selectMeituanSettingsById(id));
    }

    /**
     * 新增美团点评API配置
     */
    @ApiOperation("新增美团点评API配置")
    @PreAuthorize("@ss.hasPermi('system:settings:add')")
    @Log(title = "美团点评API配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MeituanSettings meituanSettings)
    {
        return toAjax(meituanSettingsService.insertMeituanSettings(meituanSettings));
    }

    /**
     * 修改美团点评API配置
     */
    @ApiOperation("修改美团点评API配置")
    @PreAuthorize("@ss.hasPermi('system:settings:edit')")
    @Log(title = "美团点评API配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MeituanSettings meituanSettings)
    {
        return toAjax(meituanSettingsService.updateMeituanSettings(meituanSettings));
    }

    /**
     * 通过id批量删除美团点评API配置
     */
    @ApiOperation("通过id批量删除美团点评API配置")
    @PreAuthorize("@ss.hasPermi('system:settings:remove')")
    @Log(title = "美团点评API配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(meituanSettingsService.deleteMeituanSettingsByIds(ids));
    }
}
